using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Vehicle : System.Web.UI.UserControl
{
    #region PROPERTIES

    public string BranchIdLocationList
    {
        get
        {
            object o = this.Session["_BranchIdLocationList"];
            if (o == null)
                return string.Empty;
            else
                return (string)o;
        }
        set
        {
            this.Session["_BranchIdLocationList"] = (object)value;
        }
    }

    public string CustomizedFilterCode
    {
        get
        {
            object o = this.Session["_CustomizedFilterCode"];
            if (o == null)
                return string.Empty;
            else
                return (string)o;
        }
        set { this.Session["_CustomizedFilterCode"] = (object)value; }
    }

    public bool EnableLog
    {
        get
        {
            object o = this.Session["_EnableLog"];
            if (o == null)
                return false;
            else
                return (bool)o;
        }
        set { this.Session["_EnableLog"] = (object)value; }
    }

    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        VehicleSearchManger.EnableLog = EnableLog;
        if (!Page.IsPostBack)
        {
            VehicleSearchManger.WriteLine(this.ID.ToString(), "Vehicle.ascx loaded...BranchIdLocationList:" + BranchIdLocationList);
            SearchBoxLong1.BranchIdLocationList = BranchIdLocationList;
            LoadData();
        }

        SearchBoxLong1.SearchButtonClicked += new EventHandler(SearchBoxLong1_SearchButtonClicked);
    }

    public void LoadData()
    {
        SelectViewIndex();
        VehicleSearchManger.WriteLine(this.ID.ToString(), "SelectIndex done...");
        SearchResults1.LoadData();
        VehicleSearchManger.WriteLine(this.ID.ToString(), "SearchResults loading data...done.");
        SearchBoxLong1.SearchButtonClicked += new EventHandler(SearchBoxLong1_SearchButtonClicked);
    }

    private void SearchBoxLong1_SearchButtonClicked(object sender, EventArgs e)
    {
        SearchResults1.ManufacturerId = SearchBoxLong1.SelectedManufacturerId;
        SearchResults1.ModelId = SearchBoxLong1.SelectedModelId;
        SearchResults1.YearRange = SearchBoxLong1.SelectedYearFrom + "|" + SearchBoxLong1.SelectedYearTo;
        SearchResults1.PriceRange = SearchBoxLong1.SelectedPriceFrom + "|" + SearchBoxLong1.SelectedPriceTo;
        SearchResults1.BranchIdLocationList = BranchIdLocationList;
        SearchResults1.CustomizedFilterCode = CustomizedFilterCode;

        SearchResults1.LoadData();

        VehicleMultiView.ActiveViewIndex = 0;
        //VechicleMultiView.SetActiveView(SearchResultsView);
        SearchBoxLong1.SearchButtonClicked += new EventHandler(SearchBoxLong1_SearchButtonClicked);

        divMessage.InnerHtml = string.Empty;
        if (SearchResults1.Rows <= 0)
        {
            divMessage.InnerHtml = "No records found";
        }
    }

    private void SelectViewIndex()
    {
        if (Request.QueryString["id"] != null && Request.QueryString["id"] != ""
            && Convert.ToInt32(Request.QueryString["id"]) > 0)
        {
            VehicleDetails1.VehicleId = Convert.ToInt64(Request.QueryString["id"]);
            VehicleDetails1.BackUrl = System.IO.Path.GetFileName(this.Parent.Page.Request.PhysicalPath);
            VehicleDetails1.PrinterFriendlyUrl = "/vehicle/vehiclewindowcard.aspx";

            VehicleMultiView.ActiveViewIndex = 1;
            //VechicleMultiView.SetActiveView(VehicleDetailsView);
        }
        else
        {
            VehicleMultiView.ActiveViewIndex = 0;
            //VechicleMultiView.SetActiveView(SearchResultsView);
        }
        SearchBoxLong1.SearchButtonClicked += new EventHandler(SearchBoxLong1_SearchButtonClicked);
    }

}
